package com.demo.reflect;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-13 8:06
 * @Description: ReflectTarget$
 */
public class ReflectTarget extends ReflectTargetOrigin{



	//默认带参数的构造,default,包可见
	ReflectTarget(String str){
		System.out.println("默认构造函数...");
	}

	public ReflectTarget(){
		System.out.println("公有无参构造函数...");
	}

	public ReflectTarget(char name){
		System.out.println("调用带有一个参数的构造函数，参数为："+name);
	}

	public ReflectTarget(String name,int index){
		System.out.println("调用含多个参数的构造方法,parameter is "+name+", index is "+index);
	}

	protected ReflectTarget(boolean flag){
		System.out.println("protected类型构造方法，parameter is "+flag);
	}

	private ReflectTarget(int index){
		System.out.println("私有构造方法,parameter is "+index);
	}


	//*************字段相关******************
	public String name;
	protected int index;
	char type;
	private String targetInfo;

	//************成员方法******************
	public void show1(String s){
		System.out.println("调用公共的，String参数的show1():s = "+s);
	}

	protected void show2(){
		System.out.println("调用受保护的，无参数的show2()");
	}

	void show3(){
		System.out.println("调用默认的，无参数的show3()");
	}

	private String show4(int index){
		System.out.println("调用私有的，并且有返回值的，int参数的show4(),index = "+index);
		return "show4result";
	}

	@Override
	public String toString() {
		final StringBuffer sb = new StringBuffer("ReflectTarget{");
		sb.append("name='").append(name).append('\'');
		sb.append(", index=").append(index);
		sb.append(", type=").append(type);
		sb.append(", targetInfo='").append(targetInfo).append('\'');
		sb.append('}');
		return sb.toString();
	}

	public char getType() {
		return type;
	}

	public int getIndex() {
		return index;
	}

	public String getName() {
		return name;
	}

	public String getTargetInfo() {
		return targetInfo;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTargetInfo(String targetInfo) {
		this.targetInfo = targetInfo;
	}

	public void setType(char type) {
		this.type = type;
	}

	public static void main(String[] args) throws ClassNotFoundException {
		ReflectTarget target = new ReflectTarget();
		Class reflectTargetClass1 = target.getClass();
		System.out.println("1st："+reflectTargetClass1.getName());
		Class reflectTargetClass2 = ReflectTarget.class;
		System.out.println("2nd："+reflectTargetClass2.getName());
		System.out.println(reflectTargetClass1 == reflectTargetClass2);
		Class reflectTargetClass3 = Class.forName("com.demo.reflect.ReflectTarget");
		System.out.println("3rd："+reflectTargetClass3.getName());
		System.out.println(reflectTargetClass2 == reflectTargetClass3);
	}
}
